package org.javagril.yuetong.service;

import org.apache.shiro.SecurityUtils;
import org.javagril.yuetong.bean.Carriers;
import org.javagril.yuetong.bean.RespPageBean;
import org.javagril.yuetong.bean.User;
import org.javagril.yuetong.mapper.CarriersMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;

@Service
public class CarriersService {
    @Autowired
    CarriersMapper carriersMapper;



    /*查询所有*/
    public RespPageBean getAllCarriers(Integer page, Integer size) {
        if (page != null && size != null) {
            page = (page - 1) * size;
        }
        List<Carriers> list = carriersMapper.getAllCarriers(page, size);
        Long total = carriersMapper.getTotal();
        RespPageBean respPageBean = new RespPageBean();
        respPageBean.setTotal(total);
        respPageBean.setData(list);
        return respPageBean;
    }


    /*添加承运信息*/
    public Integer addCarriers(Carriers carriers) {
        carriers.setAltertime(new Date());
        carriers.setCheckintime(new Date());
        carriers.setFkUserid(((User) SecurityUtils.getSubject().getSession().getAttribute("user")).getUserid());
        return carriersMapper.insertSelective(carriers);
    }


    /*结合调度员 查询未分配的信息*/
    public RespPageBean getCarriersByState(Integer state, Integer page, Integer size) {
        if (page != null && size != null) {
            page = (page - 1) * size;
        }
        RespPageBean respPageBean = new RespPageBean();
        respPageBean.setData(carriersMapper.getCarriersByState(state,page,size));
        respPageBean.setTotal(carriersMapper.getTotalByState(state));
        return respPageBean;
    }
}
